<?php

namespace app\admin\model;

use think\Model;

class Room extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'ty_room';

    //指定主见
    protected $pk = 'r_id';

    //只读字段
    //protected $readonly = ['name','email'];

    //自动写入时间戳
    //protected $autoWriteTimestamp = true;

    //自动写入日期
    //protected $autoWriteTimestamp = 'datetime';

    // 设置返回数据集的对象名
    protected $resultSetType = 'collection';

    // 定义时间戳字段名
    protected $createTime = 'update_time';
    protected $updateTime = 'create_time';

    public static function zselect($where=[])
    {
        $page = $_GET['page'] ?? 1;

        return self::where($where)
            ->order('r_id','desc')
            ->paginate(20, false, ['page' => $page,'query'=>request()->param()]);
    }

    public static function zcreate($param)
    {
        $room = new Room();
        return $room->saveAll($param);
    }

    public function getStatusTextAttr($value,$data)
    {
        $status = [1=>'未出租',2=>'已出租',3=>'已预定'];
        return $status[$data['status']];
    }

    public static function zupdate($data)
    {
        return self::update($data);
    }

}
